#!/usr/bin/python
# M Orsi Oct 2009
# This script implements a free-energy based permeability predictor. The input file
# "free_energy.dat", normally obtained from z-constraint simulations, is processed to
# output the corresponding permeability prediction.
#
# Usage:
# python /home/orsi/brahmsProject/analysisCode/zConstraint/permPredictor.py avgG.dat

import sys, string, math

try:
    file = sys.argv[1]
except IndexError:
    raise "Provide input file!"

inFile = open(file,'r')
lines=inFile.readlines()
inFile.close()

maxDeltaG = minDeltaG = 0.; # initialise transfer free energy values

for line in lines:
    words = string.split( line )
    deltaG = float(words[1]) # transfer free energy
    if deltaG > maxDeltaG:
        maxDeltaG = deltaG
    if deltaG < minDeltaG:
        minDeltaG = deltaG

print "Max transfer free energy: % 6.4f" % maxDeltaG
print "Min transfer free energy: % 6.4f" % minDeltaG

kB = 1.3806505e-26 # [kJ/K]
AVOGAD = 6.0221367e23 # [mol^(-1)]

kBTroom = kB * 298
kBTroom_mol = kBTroom*AVOGAD
#print kBTroom_mol

#p = 1/(maxDeltaG-minDeltaG)
#p = kBTroom_mol/(math.e**(maxDeltaG-minDeltaG))
#p = kBTroom_mol/(maxDeltaG-minDeltaG)
p = 100*kBTroom_mol/(maxDeltaG-minDeltaG)


print "Permeability predictor: %.4g" % p
